package main

import "fmt"

func main() {

	d := []interface{}{"red", "yellow", "blue", "red", 1, 1}
	uniqueSlice(d)

	var b3 = make([]int, 2)
	fmt.Printf("%+v\n", b3)

	c := &b3
	fmt.Printf("%+v\n", c)
	b3[1] = 2
	fmt.Println(b3)

	b2 := []int{1, 2, 3}
	b2[0] = 1
	fmt.Println(b2)

	a1 := [][]int{}
	b1 := []int{1, 2, 3}
	a1 = append(a1, b1)
	a1 = append(a1, []int{4, 5, 6})
	fmt.Println("a1=", a1, " || b1=", b1)
	//return

	var s []int
	fmt.Println("len=", len(s), "cap=", cap(s))

	//在使用append添加数据时,切片的地址可能会发生变化,如果容量扩充导致输出存储溢出,切片会自动寻找新的空间存储数据
	//同时也会将之前的数据进行释放
	s = append(s, 1, 2, 3)
	fmt.Println(s)

	//切片的拷贝
	a := []int{1, 2, 3, 4, 5}
	b := make([]int, 5)
	//将a切片中的数据拷贝到b中,b中要有足够的容量
	//拷贝后a,b是两个完全独立的空间,不会相互影响
	copy(b, a)
	fmt.Println("b=", b)

	b[1] = 10
	fmt.Println(b)
	fmt.Println(a)

}

func uniqueSlice(s []interface{}) {
	a := []interface{}{}

	for _, v := range s {
		breakSymbol := false
		for _, v1 := range a {
			if v == v1 {
				breakSymbol = true
				break
			}
		}
		if !breakSymbol {
			a = append(a, v)
		}

	}
	fmt.Println(a)
}
